<?php


// 处理字符串防止特殊符号引起的错误，
$process_include    = array('title', 'url');
string_pre_process($record, $process_include);
if($action == 'modify') {
    $txt_form_title = "修改地区信息";
} else {
    $txt_form_title = "新增地区信息";
}
$tbl_zone   = $_TABLES['city'];
$conn       = & get_db_conn();
$sql1="SELECT * FROM $tbl_zone ORDER BY num asc";
$rs = & $conn->GetAll($sql1);

require($abs_admin_cppath . '/header.php');
?>
<script type="text/javascript" src="<?php echo $G_web_root; ?>/js/jquery.js"></script>
<SCRIPT LANGUAGE="JavaScript" SRC="<?php echo $url_global['common']; ?>/js/Validator.js"></SCRIPT>
	<div class="datacontainer2" style="width:600px;">
<div class="header">
	&nbsp;&nbsp;<span class="font_form_head"><?php echo $txt_form_title; ?></span>
</div>
<table BORDER="0" cellpadding="0" cellspacing="0" width="100%" class="list_table">
<form action="<?php echo $mod_url['save']; ?>" method="post" name="user_data" enctype="multipart/form-data" onsubmit="return Validator.Validate(this,3);">
<SCRIPT LANGUAGE="JavaScript" SRC="<?php echo $url_global['common']; ?>/js/jquery-1.3.2.min.js"></SCRIPT>
<TR>
	<TD width="120" align="right" class="caption">名称：</TD>
	<TD class="FormCell"><input type="hidden" name="zone[site_id]" value="0" />
		<input type="text" name="zone[cname]" value="<?php echo $record['cname']; ?>" class="text" size="40"
		dataType="Require" msg="“名称”必须填写">
		<span class="mustfill">*</span>
	</TD>
</TR>
<TR>
	<TD width="120" align="right" class="caption">所属地区：</TD>
	<TD class="FormCell"><input type="hidden" name="zone[site_id]" value="0" />
	<input type="hidden" name="zone[num1]" value="<?php echo $record['num'];?>"/>
		<select name="zone[num]">
		<option value="0"  selected="true">一级地区</option>
		</select>
        <select name="zone[num1]" onchange="changenum(this.value)">
		<option value="0"  selected="true">请选择</option>
		<?php
		if($rs) {
			foreach($rs as $article) {
				if($article['num']==0&&$article['num1']==0&&$record['id']!=$article['id']){
				?>
				<option value="<?php echo $article['id'];?>" <?php if($record['num']==$article['id']){echo ' selected="true"';}?>><?php echo $article['cname'];?></option>
				<?php
				}
			}
		}?>
		</select>
        <select name="zone[num2]" id="num2">
		<option value="0"  selected="true">请选择</option>
		<?php
		if($rs&&($record['num1']||$record['num'])) {
			foreach($rs as $article) {
				if($article['num']!=0&&$article['num1']==0&&$record['id']!=$article['id']&&$record['num']==$article['num']){
				?>
				<option value="<?php echo $article['id'];?>" <?php if($record['num1']==$article['id']){echo ' selected="true"';}?>><?php echo $article['cname'];?></option>
				<?php
				}
			}
		}?>
		</select>
		<span class="mustfill">*</span>
        <br />
	</TD>
</TR>
<script>
function changenum(va){
    var op='<option value="0" >请选择</option>';
    if(va!=0){
        url = '<?php echo $G_web_root.'/common/ajax.php?action=getCity';?>';//window.location.href=url+'&cid='+va+'&num=1&noid=<?php echo $record['id'];?>';
	    $.post(url, {cid:va,num:1,noid:'<?php echo $record['id'];?>'},function(data){
	       
	       if(data['type']==1){
	           for(var i in data['data']){
	               if(data['data'][i]['id']){
	                   op+='<option value="'+data['data'][i]['id']+'">'+data['data'][i]['cname']+'</option>';
                   }
               }
	       }
           $('#num2').html(op);
	    },'json');
    }else{
        $('#num2').html(op);
    }
}
</script>
<TR>
	<TD class="FormCell" colspan="2" align="center">
		<input type="submit" value=" 保存 " class="btn">
		<input type="reset" value=" 重置 " class="btn">
		<input type="button" value=" 返回 " class="btn" onclick="location.href='<?php echo $back_url; ?>'">
		<input type="hidden" name="zone[id]" value="<?php echo $id; ?>">
		<input type="hidden" name="save" value="<?php echo $save_flag; ?>">
	</TD>
</TR>
</form>
</TABLE>
	</div>
<?php
require($abs_admin_cppath . '/footer.php');
?>